<!doctype html public "-//W3C//DTD HTML 4.0 //EN">
<?php
//$menu = array('nf_select', 'nf_create', 'logout');
//$content = array('editing/edit');
//$newsfeed_id = $newsfeed_id;
?>
<html>
	<head>
		<title>Newsfeed | <?php echo $newsfeed_title; ?></title>
		
		<link href="<?php echo base_url(); ?>assets/css/screen.css" type="text/css" rel="stylesheet" />
		
		<script src="<?php echo base_url(); ?>assets/js/jquery-1.4.4.min.js" type="text/javascript"></script>
		<script src="<?php echo base_url(); ?>assets/js/jquery.livequery.js" type="text/javascript"></script>
		<script src="<?php echo base_url(); ?>assets/js/jquery.elastic.js" type="text/javascript"></script>
		<script src="<?php echo base_url(); ?>assets/js/jquery.watermarkinput.js" type="text/javascript"></script>
		<script type="text/javascript">
			// <![CDATA[
			var path = "http://localhost/gc/uv-nf/assets/";
			$(document).ready(function(){
			  $("#extra_input1").hide();
			  $("#extra_input2").hide();
			  
				$('#shareButton').click(function(){
					var a = $("#watermark").val();
					var ext1 = $("#extra1").val();
					var ext2 = $("#extra2").val();
					var newsfeed_id = $("#newsfeed_id").val();
					var type = document.postForm.post_type[document.postForm.post_type.selectedIndex].text;
					
					progress = false;
					if((type == "Status update") && (a != "What's on your mind?")) {
					  progress = true;
					} else if(type == "X and Y are now friends") {
  				 if(ext1 == "Who is Y?") { alert("You need to fill in Extra 1"); } else { progress = true; }
  				} else if(type == "X is now friends with Y and Z") {
  				 if((ext1 == "Who is Y?") || (ext2 == "Who is Z?")) { alert("You need to fill in Extra 1 and Extra 2"); } else { progress = true; }
					} else if(type == "You poke") {
					  if(ext1 == "Who do you poke?") { alert("You need to fill in Extra 1"); } else { progress = true; }
					} else if(type == "You are poked") {
					  if(ext1 == "Who is Y?") { alert("You need to fill in Extra 1"); } else { progress = true; }
					} else if(type == "Wall message") {
					  if((ext1 == "Who posted on your wall?") || (ext2 == "What message did they leave?")) { alert("You need to fill in Extra 1 and Extra 2"); } else { progress = true; }
					} else if(type == "X and Y are in a relationship") {
					  if(ext1 == "Who is Y?") { alert("You need to fill in Extra 1"); } else { progress = true; }
					} else if(type == "X became a fan of Y") {
					  if(ext1 == "What is Y?") { alert("You need to fill in Extra 1"); } else { progress = true; }
					}
					  
					   
					if (progress) { 
						$.post(path+"php/" + "posts.php?value=" + a + "&type=" + type + "&newsfeed_id=" + newsfeed_id + "&extra1=" + ext1 + "&extra2=" + ext2, {
						}, function(response){
							$('#posting').prepend($(response).fadeIn('slow'));
							$("#watermark").val("What's on your mind?");
						});
			    }
					//alert(document.postForm.post_type[document.postForm.post_type.selectedIndex].text);
				});
				
				//post_type select changed
				$('#post_type').change(function(){
					var type = document.postForm.post_type[document.postForm.post_type.selectedIndex].text;
					
					//update comment area
					$("#extra1").val("");
          $("#extra2").val("");
          //$("#extra_input1").fadeOut(0);
          //$("#extra_input2").fadeOut(0);
          
          $(".extra_input_div:visible").fadeToggle(0);
          
					if(type == "Status update") {
						$("#watermark").delay(300).fadeIn(300);
					} else if(type == "X and Y are now friends") {
					  $("#watermark").delay(300).fadeOut(300);
						$("#extra1").val("Who is Y?");
						$("#extra_input1").delay(300).fadeIn(300);
					} else if(type == "X is now friends with Y and Z") {
					  $("#watermark").delay(300).fadeOut(300);
						$("#extra1").val("Who is Y?");
            $("#extra2").val("Who is Z?");
            $("#extra_input1").delay(300).fadeIn(300);
            $("#extra_input2").delay(300).fadeIn(300);
					} else if(type == "You poke") {
					  $("#watermark").delay(300).fadeOut(300);
						$("#extra1").val("Who do you poke?");
						$("#extra_input1").delay(300).fadeIn(300);
					} else if(type == "You are poked") {
					  $("#watermark").delay(300).fadeOut(300);
						$("#extra1").val("Who is Y?");
						$("#extra_input1").delay(300).fadeIn(300);
					} else if(type == "Wall message") {
					  $("#watermark").delay(300).fadeOut(300);
						$("#extra1").val("Who posted on your wall?");
            $("#extra2").val("What message did they leave?");
            $("#extra_input1").delay(300).fadeIn(300);
            $("#extra_input2").delay(300).fadeIn(300);
					} else if(type == "X was tagged in an album") {
					  $("#watermark").delay(300).fadeOut(300);
					} else if(type == "X and Y are in a relationship") {
					  $("#watermark").delay(300).fadeOut(300);
					  $("#extra1").val("Who is Y?");
					  $("#extra_input1").delay(300).fadeIn(300);
					} else if(type == "X became a fan of Y") {
					  $("#watermark").delay(300).fadeOut(300);
						$("#extra1").val("What is Y?");
						$("#extra_input1").delay(300).fadeIn(300);
					}
					
					UseData();
					//alert(type);
				});
				
				$('.commentMark').livequery("focus", function(e){
					var parent  = $(this).parent();
					$(".commentBox").children(".commentMark").css('width','320px');
					$(".commentBox").children("a#SubmitComment").hide();
					$(".commentBox").children(".CommentImg").hide();
					
					var getID =  parent.attr('id').replace('record-','');
					$("#commentBox-"+getID).children("a#SubmitComment").show();
					$('.commentMark').css('width','300px');
					$("#commentBox-"+getID).children(".CommentImg").show();
				});	
				
				//showCommentBox
				$('a.showCommentBox').livequery("click", function(e){
					var getpID =  $(this).attr('id').replace('post_id','');	
					
					$("#commentBox-"+getpID).css('display','');
					$("#commentMark-"+getpID).focus();
					$("#commentBox-"+getpID).children("img.CommentImg").show();
					$("#commentBox-"+getpID).children("a#SubmitComment").show();
				});	
				
				//SubmitComment
				$('a.comment').livequery("click", function(e){
					var getpID =  $(this).parent().attr('id').replace('commentBox-','');
					var comment_text = $("#commentMark-"+getpID).val();
					
					if(comment_text != "Write a comment...") {
						$.post(path+"php/"+"add_comment.php?comment_text="+comment_text+"&post_id="+getpID, {
						}, function(response){
							$('#CommentPosted'+getpID).append($(response).fadeIn('slow'));
							$("#commentMark-"+getpID).val("Write a comment...");
						});
					}
				});	
				
				//more records show
				$('a.more_records').livequery("click", function(e){
					var next =  $(this).attr('id').replace('more_','');
					
					$.post(path+"php/"+"posts.php?show_more_post="+next, {
					}, function(response){
						$('#bottomMoreButton').remove();
						$('#posting').append($(response).fadeIn('slow'));
					});
				});	
				
				//deleteComment
				$('a.c_delete').livequery("click", function(e){
					if(confirm('Are you sure you want to delete this comment?')==false)
						return false;
					
					e.preventDefault();
					var parent  = $(this).parent();
					var c_id =  $(this).attr('id').replace('CID-','');
					$.ajax({
						type:	'get',
						url:	path+"php/"+'delete_comment.php?c_id='+ c_id,
						data:	'',
						beforeSend: function(){ },
						success: function(){
							parent.fadeOut(200,function(){
								parent.remove();
							});
						}
					});
				});	
				
				/// hover show remove button
				$('.friends_area').livequery("mouseenter", function(e){
					$(this).children("a.delete").show();	
				});	
				$('.friends_area').livequery("mouseleave", function(e){
					$('a.delete').hide();	
				});	
				/// hover show remove button
				
				$('a.delete').livequery("click", function(e){
					if(confirm('Are you sure you want to delete this post?')==false)
						return false;
					
					e.preventDefault();
					var parent  = $(this).parent();
					var temp    = parent.attr('id').replace('record-','');
					var main_tr = $('#'+temp).parent();
	
					$.ajax({
						type:	'get',
						url:	path+"php/"+'delete.php?id='+ parent.attr('id').replace('record-',''),
						data:	'',
						beforeSend: function(){ },
						success: function(){
							parent.fadeOut(200,function(){
								main_tr.remove();
							});
						}
					});
				});
				
				$('textarea').elastic();
				
				jQuery(function($){
					$("#watermark").Watermark("What's on your mind?");
					$(".commentMark").Watermark("Write a comment...");
				});
				
				jQuery(function($){
					$("#watermark").Watermark("watermark","#369");
					$(".commentMark").Watermark("watermark","#EEEEEE");
				});
				
				function UseData(){
					$.Watermark.HideAll();
					//Do Stuff
					$.Watermark.ShowAll();
				}
			});
			// ]]>
		</script>
	</head>
	
	<body>
		<h1><?php echo $newsfeed_title; ?> - as <?php echo $newsfeed_who; ?></h1>
			<div align="center">
				<form action="" method="post" name="postForm">
				  <input type="hidden" name="newsfeed_id" id="newsfeed_id" value="<?php echo $newsfeed_id ?>">
					<div class="UIComposer_Box">
					<span style="float:left">
            What type of update do you want?
            <select name="post_type" id="post_type">
              <option value="status_update">Status update</option>
              <option value="friends_1">X and Y are now friends</option>
              <option value="friends_2">X is now friends with Y and Z</option>
              <option value="you_poke">You poke</option>
              <option value="you_poked">You are poked</option>
              <option value="wall_message">Wall message</option>
              <option value="tagged_album">X was tagged in an album</option>
              <option value="relationship">X and Y are in a relationship</option>
              <option value="fan_of">X became a fan of Y</option>
            </select>
          </span>
						<span class="w">
							<textarea class="input" id="watermark" name="watermark" style="height:20px" cols="60"></textarea>
						</span>
              <div id="extra_input">
                <div id="extra_input1" class="extra_input_div">
                  <label for="extra1">Extra 1</label><input type="text" name="extra1" value="" id="extra1" class="extra_text">
                </div>
                <div id="extra_input2" class="extra_input_div">
                  <label for="extra2">Extra 2</label><input type="text" name="extra2" value="" id="extra2" class="extra_text">
                </div>
              </div>
						<br clear="all" />
						
						<div align="left" style="height:60px; padding:10px 5px;">
							<a id="shareButton" style="float:right" class="small button Detail">Share</a>
							<br clear="all" />
						</div>
					</div>
				</form>
				
				<br clear="all" />
				<div id="posting" align="center">
					<?php
						include_once('assets/php/posts.php');
					?>  
				</div>
			</div>
		<br clear="all" /><br clear="all" /><br clear="all" /><br clear="all" />
	</body>
</html>
